﻿using System;
using System.Collections.Generic;
using System.Collections;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class admin_CompanyInfo_Location : System.Web.UI.Page
{
    public ArrayList accountarr = null;
    public int id = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            accountarr = (ArrayList)DB.getArrLocation("");
            if (Request.QueryString["id"] != null) id = int.Parse(Request.QueryString["id"].ToString());

            lb_id.Text = id.ToString();

            RE_GenericBean location = DB.getLocation(id);
            tb_loccode.Text = location.strC1;
            tb_locname.Text = location.strC2;
            tb_addr.Text = location.strC3;
            tb_addr2.Text = location.strC4;
            tb_city.Text = location.strC5;
            tb_state.Text = location.strC6;
            tb_zip.Text = location.strC7;
            tb_country.Text = location.strC8;
            tb_phone1.Text = location.strC9;
            tb_fax.Text = location.strC10;

            if (location.intC1 != 0)
            {
                habilitocampos(false);
                HyperLink1_ModalPopupExtender.Show();
            }
        }
        else {
            id = int.Parse(lb_id.Text);
        }
    }

    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        bool actualiza=false;
        RE_GenericBean location = new RE_GenericBean();

        location.intC1 = int.Parse(lb_id.Text);
        location.strC1 = tb_loccode.Text;
        location.strC2 = tb_locname.Text;
        location.strC3 = tb_addr.Text;
        location.strC4 = tb_addr2.Text;
        location.strC5 = tb_city.Text;
        location.strC6 = tb_state.Text;
        location.strC7 = tb_zip.Text;
        location.strC8 = tb_country.Text;
        location.strC9 = tb_phone1.Text;
        location.strC10 = tb_fax.Text;

        if (location.intC1 != 0) actualiza = true;

        if (DB.InsertaLocation(location, actualiza)) {
            Response.Redirect("CompanyInfo_Location.aspx");
        }

    }
    protected void LinkButton2_Click(object sender, EventArgs e)
    {
        habilitocampos(true);
        HyperLink1_ModalPopupExtender.Show();
    }
    protected void LinkButton3_Click(object sender, EventArgs e)
    {
        id = int.Parse(lb_id.Text);
        if (id != 0)
        {
            int result = DB.DeleteLocation(id);
            Response.Redirect("CompanyInfo_Location.aspx");
        }
    }

    private void habilitocampos(bool estado)
    {
        tb_loccode.Enabled=estado;
        tb_locname.Enabled = estado;
        tb_addr.Enabled = estado;
        tb_addr2.Enabled = estado;
        tb_city.Enabled = estado;
        tb_state.Enabled = estado;
        tb_zip.Enabled = estado;
        tb_country.Enabled = estado;
        tb_phone1.Enabled = estado;
        tb_fax.Enabled = estado;
    }
}